package io.xxx.xbutler.domain;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

@Data
@Accessors(chain = true)
@TableName(autoResultMap = true)
public class Callback {

    @TableId
    private Long id;

    private String merchantNo;

    private Integer type;

    private String serialNo;

    private String robotId;

    private String robotSerialNo;

    private Integer code;

    private String message;

    private LocalDateTime timestamp;

    /**
     * Context中的Data字段，有对象和数组两种数据结构。
     */
    @TableField(typeHandler = Fastjson2TypeHandler.class)
    private Object data;

    @TableField(typeHandler = Fastjson2TypeHandler.class)
    private JSONObject context;

    private String sign;

    /**
     * 0 - 没有处理
     * 1 - 正在处理
     * 2 - 处理成功
     * 3 - 处理失败
     * 4 - 跳过处理
     */
    private Integer status;

    private String exception;

    private LocalDateTime createdTime;

    private LocalDateTime updatedTime;

    public boolean isSuccess() {
        return code == 1;
    }
}
